from bs4 import BeautifulSoup

html = """
<html>
<head><title>黑马程序员</title></head>
<body>
    <p id="test01">软件测试</p>
    <p id="test02">2020年</p>
    <a href="/api.html">接口测试</a>
    <a href="/web.html">Web自动化测试</a>
    <a href="/app.html">APP自动化测试</a>
</body>
</html>
"""

soup = BeautifulSoup(html, "html.parser")
# 获取title
print("title=={}".format(soup.title))
print("title=={}".format(soup.title.string))
print("title=={}".format(soup.title.name))

# 返回第一个匹配的标签
print("p=={}".format(soup.p["id"]))
print("p=={}".format(soup.p.get("id")))

# 获得全部标签
for a in soup.find_all("a"):
    print(f"href={a.get('href')},text={a.string}")